package com.ma5d.driver.customer.controller;

import com.ma5d.driver.common.login.UserLogin;
import com.ma5d.driver.common.result.Result;
import com.ma5d.driver.common.util.AuthContextHolder;
import com.ma5d.driver.customer.service.CustomerService;
import com.ma5d.driver.model.form.UpdateWxPhoneForm;
import com.ma5d.driver.model.vo.customer.CustomerLoginVo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Resource
    private CustomerService customerService;

    @GetMapping("/login/{code}")
    public Result<String> wxLogin(@PathVariable String code) {
        return Result.ok(customerService.login(code));
    }

    @UserLogin
    @GetMapping("/getCustomerLoginInfo")
    public Result<CustomerLoginVo> getCustomerLoginInfo() {
        Long customerId = AuthContextHolder.getUserId();
        return Result.ok(customerService.getCustomerVo(customerId));
    }

    @UserLogin
    @PostMapping("/updateWxPhone")
    public Result<Boolean> updateWxPhone(@RequestBody UpdateWxPhoneForm updateWxPhoneForm) {
        updateWxPhoneForm.setCustomerId(AuthContextHolder.getUserId());
        return Result.ok(customerService.updateWxPhoneNumber(updateWxPhoneForm));
    }

}
